"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
from typing import List

from do.build_do import BuildDo
from server import db_session


class BuildDao:

    def get(self, build_id) -> BuildDo:
        # 根据id返回数据
        return db_session.query(BuildDo).filter_by(id=build_id).first()

    def list(self) -> List[BuildDo]:
        # 返回所有
        return db_session.query(BuildDo).all()

    def save(self, build_do: BuildDo):
        # 新增数据
        db_session.add(build_do)
        db_session.commit()
        return build_do.id

    def update(self, build_do: BuildDo):
        # 修改数据
        db_session.query(BuildDo).filter_by(id=build_do.id).update(build_do.as_dict())
        db_session.commit()
        return build_do.id

    def delete(self, build_id):
        # 删除数据
        db_session.query(BuildDo).filter_by(id=build_id).delete()
        db_session.commit()
        return build_id
